import os

"""
根据图片的编号删除数据集
"""

############需要修改###################
# 提供要删除的图片的编号列表
image_numbers_to_delete = [992,1040,1455,4008]
 # 编号列表

# 图片和txt文件的文件夹路径
images_folder = "/home/hw/dataset/cone_total_new/images"
labels_folder = "/home/hw/dataset/cone_total_new/labels"
#####################################

def delete_images_and_labels(image_numbers, images_folder, labels_folder):
    # 遍历每个提供的图片编号
    for number in image_numbers:
        # 构造图片和txt文件的路径
        image_name = f"{number}.jpg"
        txt_name = f"{number}.txt"
        image_path = os.path.join(images_folder, image_name)
        txt_path = os.path.join(labels_folder, txt_name)

        # 如果图片存在则删除
        if os.path.exists(image_path):
            os.remove(image_path)
            print(f"Deleted image: {image_name}")

        # 如果txt文件存在则删除
        if os.path.exists(txt_path):
            os.remove(txt_path)
            print(f"Deleted label: {txt_name}")

if __name__ == "__main__":

    # 调用函数删除图片和txt文件
    delete_images_and_labels(image_numbers_to_delete, images_folder, labels_folder)